#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */


void main( int argc, char **argv ) {
	
      int fd; /* File descriptor for the port */


      fd = open( argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
      if (fd == -1)
      {
       /*
	* Could not open the port.
	*/

	printf("open_port: Unable to open %s - %s\n", argv[1], strerror( errno ));
      }
      else
	fcntl(fd, F_SETFL, 0);



    struct termios options;

    /*
     * Get the current options for the port...
     */

    tcgetattr(fd, &options);

    /*
     * Set the baud rates to 9600...
     */

    cfsetispeed(&options, B9600);
    cfsetospeed(&options, B9600);
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;
    options.c_oflag &= ~OPOST; //raw output

    /*
     * Enable the receiver and set local mode...
     */

    options.c_cflag |= (CLOCAL | CREAD);

    /*
     * Set the new options for the port...
     */

    tcsetattr(fd, TCSANOW, &options);

	char buffer[ 10 ];
	buffer[ 0 ] = 0xa2;
	buffer[ 1 ] = 0x02;
	buffer[ 2 ] = 0x0f;
	buffer[ 3 ] = 0x12;
	buffer[ 4 ] = 0x56;
	buffer[ 5 ] = 0x11;
	
    int n = write( fd, buffer, 6);
    if (n < 0)
      fputs("write() of 8 bytes failed!\n", stderr);


    close(fd);

}